package lang

import (
	"jvm/native"
	"jvm/rtda"
	. "jvm/typedef"
	"math"
)

const jlFloat = "java/lang/Float"

func init() {
	native.Register(jlFloat, "floatToRawIntBits", "(F)I", floatToRawIntBits)
	native.Register(jlFloat, "intBitsToFloat", "(I)F", intBitsToFloat)
}

// public static native int floatToRawIntBits(float value);
func floatToRawIntBits(frame *rtda.Frame) {
	val := frame.LocalVars().GetFloat(0)
	bits := math.Float32bits(float32(val))
	frame.OPStack().PushInt(I4(bits))
}

// public static native float intBitsToFloat(int bits);
func intBitsToFloat(frame *rtda.Frame) {
	bits := frame.LocalVars().GetInt(0)
	value := math.Float32frombits(uint32(bits)) // todo
	frame.OPStack().PushFloat(F4(value))
}
